package com.yzz.shopping.domain.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.sixby.common.CommonConstants;
import com.sixby.domain.dao.ShopInfoMapper;
import com.sixby.domain.dao.SysDictionaryMapper;
import com.sixby.domain.entity.ShopInfo;
import com.sixby.domain.entity.SysDictionary;

@Service
@Transactional
public class ShopInfoService {
    @Autowired
    private SysDictionaryMapper sysDictionaryMapper;

    @Autowired
    private ShopInfoMapper shopInfoMapper;

    public List<Map<String, String>> getCategoryAll() {
        List<Map<String, String>> res = null;
        List<String> dict = new ArrayList<>();
        dict.add("shopInfoType");
        List<SysDictionary> categoryList = sysDictionaryMapper.findByCode(dict);
        if (categoryList != null && !categoryList.isEmpty()) {
            res = new ArrayList<>();
            for (SysDictionary sysDictionary : categoryList) {
                Map<String, String> dictMap = new HashMap<>();
                dictMap.put("key", sysDictionary.getId());
                dictMap.put("value", sysDictionary.getName());
                res.add(dictMap);
            }
        }
        return res;
    }

    public List<ShopInfo> getCategoryShopInfo(String categoryId) {
        ShopInfo shopInfo = new ShopInfo();
        shopInfo.setShopInfoType(categoryId);
        shopInfo.setStatus(CommonConstants.STATUS_VALID);
        return shopInfoMapper.findByPage(shopInfo);
    }
}
